import * as user from '@/api/user.js'
export default {
	data() {
		return {
			NavHeight: this.NavHeight,
			token: '',
			avatar: '../../static/user/avatar.png',
			loginInfo: {
				code: '',
				phoneCode: ''
			}, //登录信息
			userInfo: {
				phone: '',
				avatar: '',
				nickname: ''
			}, //用户信息
			postInfo: {
				avatar: '',
				nickname: ''
			}, //上传用户信息
			menuList: [{
					imgUrl: '../../static/user/icon-1.png',
					value: '浏览记录',
					to: "/pages/user/browsel/index"
				},
				// {
				// 	imgUrl: '../../static/user/icon-2.png',
				// 	value: '我的发布',
				// 	to: '/pages/user/myRelease/myRelease'
				// },
				{
					imgUrl: '../../static/user/icon-3.png',
					value: '拨打记录',
					to: "/pages/user/dial/index"
				},
				// {
				// 	imgUrl: '../../static/user/icon-4.png',
				// 	value: '联系平台'
				// },
			]
		}
	},

	onShow() {
		this.getMemberInfo()
	},
	onLoad(option) {

	},

	methods: {
		getPhoneNumber(e) {
			let that = this
			that.loginInfo.phoneCode = e.detail.code
			if (that.loginInfo.phoneCode) {
				uni.login({
					provider: 'weixin',
					onlyAuthorize: true,
					success: function(loginRes) {
						that.loginInfo.code = loginRes.code
						that.wxLogin()
					}
				});
			}

		},
		// go() {
		// 	uni.navigateToMiniProgram({
		// 		appId: 'wxdc1872c7cca4515a',
		// 		path: '',
		// 		extraData: {
		// 			'data1': 'release'
		// 		},
		// 		success(res) {
		// 			// 打开成功
		// 		}
		// 	})
		// },
		navTo(item, index) {
			if (this.token) {
				if (item.value != '联系平台') {
					this.$tools.navigate(item.to)
				} else {
					user.getCustomerService().then(res => {
						uni.makePhoneCall({
							phoneNumber: res.data //仅为示例
						});
					})
				}
			} else {
				if (index == 3) {
					user.getCustomerService().then(res => {
						uni.makePhoneCall({
							phoneNumber: res.data //仅为示例
						});
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '请登录',
						duration: 2000
					});
				}

			}

		},
		// 微信登录
		wxLogin() {
			let that = this
			user.wxLogin(this.loginInfo).then(res => {
				uni.setStorage({
					key: 'token',
					data: res.data.token,
					success: function() {
						that.token = res.data.token
						that.getMemberInfo()
					}
				});
			})
		},
		//获取用户信息
		getMemberInfo() {
			this.token = uni.getStorageSync('token')
			if (this.token) {
				user.getMemberInfo().then(res => {
					this.userInfo = res.data
				})
			}

		},
		//获取用户信息
		getUserInfo() {
			let that = this
			if (this.userInfo.wxname != 1) {
				wx.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						that.postInfo.avatar = res.userInfo.avatarUrl
						that.postInfo.nickname = res.userInfo.nickName
						user.memberBdWx(that.postInfo).then(res => {
							that.getMemberInfo()
						})
					}
				})
			}
		},
		//发布房源
		goHome() {
			if (this.token) {
				this.$tools.navigate('/pages/user/releaseHome/releaseHome')
			} else {
				uni.showToast({
					icon: 'none',
					title: '请登录',
					duration: 2000
				});
			}
		},
		//求租
		goRent() {
			if (this.token) {
				uni.showToast({
					icon: 'none',
					title: '正在开发,敬请期待',
					duration: 2000
				});
			} else {
				uni.showToast({
					icon: 'none',
					title: '请登录',
					duration: 2000
				});
			}
		}

	}
}
